/*************************************************************************
 *                  HONGLING CAPITAL CONFIDENTIAL AND PROPRIETARY
 *
 *                COPYRIGHT (C) HONGLING CAPITAL CORPORATION 2012
 *    ALL RIGHTS RESERVED BY HONGLING CAPITAL CORPORATION. THIS PROGRAM
 * MUST BE USED  SOLELY FOR THE PURPOSE FOR WHICH IT WAS FURNISHED BY
 * HONGLING CAPITAL CORPORATION. NO PART OF THIS PROGRAM MAY BE REPRODUCED
 * OR DISCLOSED TO OTHERS,IN ANY FORM, WITHOUT THE PRIOR WRITTEN
 * PERMISSION OF HONGLING CAPITAL CORPORATION. USE OF COPYRIGHT NOTICE
 DOES NOT EVIDENCE PUBLICATION OF THE PROGRAM.
 *                  HONGLING CAPITAL CONFIDENTIAL AND PROPRIETARY
 *************************************************************************/

package com.hongling.uc.transform;

import com.hongling.common.transform.DataTransform;
import com.hongling.uc.domain.UserDTO;
import com.hongling.uc.mapping.User;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * {@link com.hongling.uc.mapping.User}<->{@link com.hongling.uc.domain.UserDTO}互转辅助对象。
 *
 * @author hongchao zhao at 2019-7-29 12:47
 */
public class UserDT implements DataTransform<User, UserDTO> {

    @Override
    public UserDTO from(User user) {
        if (user == null) {
            return null;
        }
        UserDTO userDTO = new UserDTO();
        userDTO.setId(user.getId());
        userDTO.setUserName(user.getUserName());
        userDTO.setPassword(user.getPassword());
        userDTO.setAge(user.getAge());
        return userDTO;
    }

    @Override
    public UserDTO from(Map<String, Object> map) {
        return null;
    }

    @Override
    public List<UserDTO> fromByList(List<User> list) {
        if (list == null) {
            return null;
        }
        List<UserDTO> userDTOList = new ArrayList<>();
        for (User user : list) {
            UserDTO userDTO = from(user);
            userDTOList.add(userDTO);
        }
        return userDTOList;
    }

    @Override
    public List<UserDTO> fromByListMap(List<Map<String, Object>> list) {
        return null;
    }

    @Override
    public User to(UserDTO userDTO) {
        if (userDTO == null) {
            return null;
        }
        User user = new User();
        user.setId(userDTO.getId());
        user.setUserName(userDTO.getUserName());
        user.setPassword(userDTO.getPassword());
        user.setAge(userDTO.getAge());
        return user;
    }
}
